/************************************************************
 * Copyright (C), 2022-2030, ripnano. Co., Ltd.
 * FileName:        form_setting_upgrade.h
 * Author:          Dan Yin
 * Date:            2023-08-10
 * Description:     the class of version setting window
 * Version:         1.0.0.0
 **********************************************************/

#ifndef FORM_SETTING_UPGRADE_H
#define FORM_SETTING_UPGRADE_H

// add necessary includes here
#include "ui/defines/global.h"

namespace Ui {
class FormSettingUpgrade;
}

class FormSettingUpgrade : public QWidget
{
    Q_OBJECT

public:
    // Get an instance of "FormSettingUpgrade" class, if exist, return it
    static FormSettingUpgrade* getInstance(QWidget *pParent = nullptr);

signals:
    // Upgrade IAP and APP
    int signalStartupUpgrade(QString sFileName, bool bIAP, bool bAPP, unsigned int unCanId);

private slots:
    // Start upgrade
    void on_pushButton_Startup_clicked();

    // Enable/Disable the upgrade button after click the checkbox
    void on_checkBox_IAP_stateChanged(int arg1);

    // Enable/Disable the upgrade button after click the checkbox
    void on_checkBox_APP_stateChanged(int arg1);

    // The slot that guard upgrade process
    void slotUpgradeGuard();

    // Get the max range of the progress
    void slotProgressInit(int nMin, int nMax, bool bApp);

    // Get the value of the progress
    void slotProgressValue(int nValue, bool bApp);

    // Get the result of upgrade
    void slotUpgradeResult(int nErrCode, bool bApp);

protected:
    // Triggers an event before it is switch language
    void changeEvent(QEvent *event);

private:
    // The default constructor
    explicit FormSettingUpgrade(QWidget *parent = nullptr);

    // The default destructor
    virtual ~FormSettingUpgrade();

    // After constructing object, initialize the object
    void _initialze();

    // Init the window style
    void _initUi();

private:
    Ui::FormSettingUpgrade *ui;

    QThread                         *m_pWorker = nullptr;
    QTimer                          *m_pUpgradeGuard = nullptr;
};

#endif // FORM_SETTING_UPGRADE_H
